define
(
    ["require",
     "lib/knockout",
     "../Types"],
    function (require, ko, Types)
    {
        ko.bindingHandlers.selectedTabBind = 
        {
            init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)
            {
                // Create computed observable that will be executed whenever property changes
                ko.computed(function()
                {
                    var selectedTabProperty = valueAccessor();
                    var selectedTabValue = ko.utils.unwrapObservable(selectedTabProperty);
                    $(element).find("a[href='#" + selectedTabValue + "']").tab('show');
                });

                $(element).find("li > a[data-toggle='tab']").click(function()
                {
                    var href = $(this).attr('href');
                    var tab = href.replace(/#/g, "");
                    valueAccessor()(tab);
                });
            }
        };
    }
);